package yagwl.client.widget;

import com.google.gwt.user.client.ui.Widget;

/**
 * Represents a field in a form. Uses method chaining
 */
public class FormField {
  private String label;
  private Widget dataWidget;
  private boolean required = true;
  private boolean visible = true;
  private boolean spanColumns = false;
  private boolean lastFieldInColumn = false;
  private boolean columnHeader = false;

  public FormField() {
  }

  public String getLabel() {
    return label;
  }

  public FormField setLabel(String label) {
    this.label = label;
    return this;
  }

  public Widget getDataWidget() {
    return dataWidget;
  }

  public FormField setDataWidget(Widget wiget) {
    this.dataWidget = wiget;
    return this;
  }

  public boolean isRequired() {
    return required;
  }

  public FormField setRequired(boolean required) {
    this.required = required;
    return this;
  }

  public boolean isVisible() {
    return visible;
  }

  public FormField setVisible(boolean visible) {
    this.visible = visible;
    return this;
  }

  /**
   * Whether the field spans multiple columns in a form. Default is false.
   * Applicable for horizontal tab flow only.
   */
  public boolean isSpanColumns() {
    return spanColumns;
  }

  public FormField setSpanColumns(boolean spanColumns) {
    this.spanColumns = spanColumns;
    return this;
  }

  /**
   * Whether it is the last field in a column. Default is false. Applicable for
   * vertical tab flow only.
   */
  public boolean isLastFieldInColumn() {
    return lastFieldInColumn;
  }

  public FormField setLastFieldInColumn(boolean lastFieldInColumn) {
    this.lastFieldInColumn = lastFieldInColumn;
    return this;
  }

  public boolean isColumnHeader() {
    return columnHeader;
  }

  /**
   * Set this field as column header. Default is false. Applicable for vertical
   * tab flow only. Use setLabel() to set column header string.
   */
  public FormField setColumnHeader(boolean columnHeader) {
    this.columnHeader = columnHeader;
    return this;
  }
}